package cn.hmcode.device.controller;

import cn.hmcode.device.constance.MqttConstants;
import cn.hmcode.device.dto.ChargingDto;
import cn.hmcode.device.mqtt.MqttProducer;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private MqttProducer mqttProducer;

    @GetMapping
    public String sayHi(){
        ChargingDto chargingDto = new ChargingDto();
        chargingDto.setOrderNo("666");
        chargingDto.setGunId(1);
        chargingDto.setPileId(666);
        chargingDto.setMsg("start_charging");
        mqttProducer.send(MqttConstants.TOPIC_START_CHARGING+chargingDto.getPileId(), JSON.toJSONString(chargingDto));
        return "ok";
    }

}
